package com.isccp.efi.util;
import com.dpcaauto.EsbService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class GetDataUtil {


    @Value("${efiws.url}")
    private String efiWsUrl;

    public      String synPackingCardService(String uc,String userName,String password) {
        String esbHeaderStr = "<RequestHead><RequestID>222222</RequestID><SourceSystem>111</SourceSystem><TargetSystem>EFI</TargetSystem><ServiceName>EFI_SynPackingCardService</ServiceName></RequestHead>";
        String esbPayloadStr="<RequestBody><uc>"+uc+"</uc><userName>"+userName+"</userName><password>"+password+"</password></RequestBody>";
        JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
        factoryBean.setClientFactoryBean(new ClientFactoryBeanImpl());
        factoryBean.setAddress(efiWsUrl);
        factoryBean.setServiceClass(EsbService.class);
        Object obj = factoryBean.create();
        EsbService userService = (EsbService) obj;
        String data=userService.e43esbServiceOperation(esbHeaderStr, esbPayloadStr);
        return data;
    }
    public   String dataRecService(String type,String objId) {
        String esbHeaderStr = "<RequestHead><RequestID>222222</RequestID><SourceSystem>111</SourceSystem><TargetSystem>EFI</TargetSystem><ServiceName>EFI_DataReceiptService</ServiceName></RequestHead>";
        String day=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String esbPayloadStr="<RequestBody><type>"+type+"</type><dataId>"+objId+"</dataId><receiveTime>"+day+"</receiveTime></RequestBody>";
        JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
        factoryBean.setClientFactoryBean(new ClientFactoryBeanImpl());
        factoryBean.setAddress(efiWsUrl);
        factoryBean.setServiceClass(EsbService.class);
        Object obj = factoryBean.create();
        EsbService userService = (EsbService) obj;
        String data=userService.efiDataReceipt(esbHeaderStr, esbPayloadStr);
        return data;
    }

    public static void main(String[] args) throws IOException {
//        System.setProperty("http.proxyHost", "127.0.0.1");
//        System.setProperty("http.proxyPort", "8888");
//      System.out.print(synPackingCardService("VD","M803960001","E79E1B21EE092106459B759FC661BD14"));


    }


}
